home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / c / ObjectiveGT1_0.lha / Examples / Lattice / viewfile_wrong.c < prev    next >
C/C++ Source or Header  |  1992-10-21  |  9KB  |  310 lines

  1. /*
  2. ** $Filename: viewfile_wrong.c $
  3. ** $Release : 1.0              $
  4. ** $Revision: 1.258            $
  5. ** $Date    : 21/10/92         $
  6. **
  7. **
  8. ** (C) Copyright 1992 Davide Massarenti
  9. **              All Rights Reserved
  10. **
  11. ** SAS 5.10: lc -O -v -L+OGTglue.lib viewfile_wrong.c
  12. **
  13. */
  14.  
  15. #include <OGT/ObjectiveGadTools.h>
  16.  
  17. #define ARGS_TEMPLATE "FILE/K,FONT/K,SIZE/N"
  18. #define ARGS_FILE       (0)
  19. #define ARGS_FONT       (1)
  20. #define ARGS_SIZE       (2)
  21. #define ARGS_NUMOF      (3)
  22.  
  23. static LONG args[ ARGS_NUMOF ];
  24.  
  25. #define GADGETID_SHOWLIST  (1)
  26.  
  27. static char Class_AslReq  [] =   ASLREQ_OGT_CLASS;
  28. static char Class_Scroller[] = SCROLLER_OGT_CLASS;
  29. static char Class_Showlist[] = SHOWLIST_OGT_CLASS;
  30.  
  31. struct TextAttr   MyAttr = { NULL, 8 };
  32. struct TextFont  *MyFont;
  33.  
  34. APTR              VInfo;
  35. struct Window    *Win;
  36. Object          **Gads;
  37. struct RDArgs    *Ra;
  38.  
  39.  
  40. struct TagItem WindowDescTags[] =
  41. {
  42.    { OVI_GimmeZeroZero    , TRUE                                  },
  43.    { OVI_AdaptWidthToFont , TRUE                                  },
  44.    { OVI_AdaptHeightToFont, TRUE                                  },
  45.    { OGT_ScaleLeft        , OGT_FontRelative                      },
  46.    { OGT_ScaleTop         , OGT_FontRelative                      },
  47.    { OGT_ScaleWidth       , OGT_FontRelative                      },
  48.    { OGT_ScaleHeight      , OGT_FontRelative                      },
  49.    { OGT_DomainXscale     , ~0                                    },
  50.    { OGT_DomainYscale     , ~0                                    },
  51.    { WA_Title             , (ULONG)"ViewFile"                     },
  52.    { WA_Activate          , TRUE                                  },
  53.    { WA_SmartRefresh      , TRUE                                  },
  54.    { WA_NoCareRefresh     , TRUE                                  },
  55.    { WA_DepthGadget       , TRUE                                  },
  56.    { WA_SizeGadget        , TRUE                                  },
  57.    { WA_SizeBBottom       , TRUE                                  },
  58.    { WA_SizeBRight        , TRUE                                  },
  59.    { WA_DragBar           , TRUE                                  },
  60.    { WA_Left              , 400                                   },
  61.    { WA_Top               , 150                                   },
  62.    { WA_InnerWidth        , 306                                   },
  63.    { WA_InnerHeight       , 120                                   },
  64.    { WA_MaxWidth          , -1                                    },
  65.    { WA_MaxHeight         , -1                                    },
  66.    { WA_IDCMP             , IDCMP_CLOSEWINDOW | IDCMP_IDCMPUPDATE },
  67.    { WA_CloseGadget       , TRUE                                  },
  68.    { TAG_DONE                                                     }
  69. };
  70.  
  71.  
  72. struct TagItem Object1Desc[] = /* ASLREQ_OGT_CLASS */
  73. {
  74.    { OGT_SetDimReference, OGT_X_Dim_Relative },
  75.    { OGT_SetPosHandle   , OGT_Y_Bottom       },
  76.    { GA_RelBottom       , 0                  },
  77.    { GA_Height          , 14                 },
  78.  
  79.    { GA_Text            , (ULONG)"_F"        },
  80.    { OGT_TextPlacement  , OGT_Text_HIDE      },
  81.  
  82.    { OGTAR_Type         , ASL_FileRequest    },
  83.    { OGTAR_ShowSelected , TRUE               },
  84.    { TAG_DONE                                }
  85. };
  86.  
  87. struct TagItem Object1Post[] =
  88. {
  89.    { OGTAR_FullFileName },
  90.    { TAG_DONE           }
  91. };
  92.  
  93.  
  94. struct TagItem Object2Desc[] = /* SCROLLER_OGT_CLASS */
  95. {
  96.    { GA_Immediate       , TRUE                                    },
  97.    { GA_FollowMouse     , TRUE                                    },
  98.    { GA_RelVerify       , TRUE                                    },
  99.    { ICA_TARGET         , NULL                                    },
  100.  
  101.    { OGT_SetDimReference, OGT_X_Dim_Relative | OGT_Y_Dim_Relative },
  102.    { GA_RightBorder     , TRUE                                    },
  103.  
  104.    { PGA_Freedom        , FREEVERT                                },
  105.    { TAG_DONE                                                     }
  106. };
  107.  
  108.  
  109. struct TagItem Object3Desc[] = /* SCROLLER_OGT_CLASS */
  110. {
  111.    { GA_Immediate       , TRUE                                    },
  112.    { GA_FollowMouse     , TRUE                                    },
  113.    { GA_RelVerify       , TRUE                                    },
  114.    { ICA_TARGET         , NULL                                    },
  115.  
  116.    { OGT_SetDimReference, OGT_X_Dim_Relative | OGT_Y_Dim_Relative },
  117.    { GA_BottomBorder    , TRUE                                    },
  118.  
  119.    { PGA_Freedom        , FREEHORIZ                               },
  120.    { TAG_DONE                                                     }
  121. };
  122.  
  123.  
  124. struct TagItem Object4Desc[] = /* SHOWLIST_OGT_CLASS */
  125. {
  126.    { GA_ID              , GADGETID_SHOWLIST                     },
  127.    { OGT_AppGadget      , TRUE                                  },
  128.    { GA_Immediate       , TRUE                                  },
  129.    { GA_FollowMouse     , TRUE                                  },
  130.    { GA_RelVerify       , TRUE                                  },
  131.    { ICA_TARGET         , NULL                                  },
  132.  
  133.    { OGT_SetDimReference, OGT_X_Dim_Relative|OGT_Y_Dim_Relative },
  134.    { GA_Height          , -14                                   },
  135.  
  136.    { OGTSL_UseNumPad    , TRUE                                  },
  137.    { TAG_DONE                                                   }
  138. };
  139.  
  140. struct OGT_ObjectSettings ListOfObjects[] =
  141. {
  142.    { Class_AslReq  , Object1Desc, Object1Post, OGT_NOOBJECT, OGT_NOOBJECT },
  143.    { Class_Scroller, Object2Desc, NULL       , OGT_NOOBJECT, OGT_NOOBJECT },
  144.    { Class_Scroller, Object3Desc, NULL       , OGT_NOOBJECT, OGT_NOOBJECT },
  145.    { Class_Showlist, Object4Desc, NULL       , OGT_NOOBJECT, OGT_NOOBJECT },
  146.    { NULL                                                                 },
  147. };
  148.  
  149.  
  150.  
  151. struct TagItem Obj2toObj4[] =    /* SCROLLER_OGT_CLASS to SHOWLIST_OGT_CLASS */
  152. {
  153.    { PGA_Top , OGTSL_VertPos },
  154.    { TAG_DONE                }
  155. };
  156.  
  157.  
  158. struct TagItem Obj3toObj4[] =    /* SCROLLER_OGT_CLASS to SHOWLIST_OGT_CLASS */
  159. {
  160.    { PGA_Top , OGTSL_HoriPos },
  161.    { TAG_DONE                }
  162. };
  163.  
  164.  
  165. struct TagItem Obj4toObj2[] =    /* SHOWLIST_OGT_CLASS to SCROLLER_OGT_CLASS */
  166. {
  167.    { OGTSL_VertPos    , PGA_Top     },
  168.    { OGTSL_VertTotal  , PGA_Total   },
  169.    { OGTSL_VertVisible, PGA_Visible },
  170.    { TAG_DONE                       }
  171. };
  172.  
  173. Tag Obj4toObj2Filter[] =
  174. {
  175.    OGTSL_VertPos    ,
  176.    OGTSL_VertTotal  ,
  177.    OGTSL_VertVisible,
  178.    TAG_DONE
  179. };
  180.  
  181.  
  182. struct TagItem Obj4toObj3[] =    /* SHOWLIST_OGT_CLASS to SCROLLER_OGT_CLASS */
  183. {
  184.    { OGTSL_HoriPos    , PGA_Top     },
  185.    { OGTSL_HoriTotal  , PGA_Total   },
  186.    { OGTSL_HoriVisible, PGA_Visible },
  187.    { TAG_DONE                       }
  188. };
  189.  
  190. Tag Obj4toObj3Filter[] =
  191. {
  192.    OGTSL_HoriPos    ,
  193.    OGTSL_HoriTotal  ,
  194.    OGTSL_HoriVisible,
  195.    TAG_DONE
  196. };
  197.  
  198.  
  199. struct TagItem Obj4toObj1[] =    /* SHOWLIST_OGT_CLASS to SCROLLER_OGT_CLASS */
  200. {
  201.    { OGT_DroppedIcon, OGTAR_FullFileName },
  202.    { TAG_DONE                            }
  203. };
  204.  
  205. Tag Obj4toObj1Filter[] =
  206. {
  207.    OGT_DroppedIcon,
  208.    TAG_DONE
  209. };
  210.  
  211.  
  212. struct TagItem Obj1toObj4[] =    /* ASLREQ_OGT_CLASS to SHOWLIST_OGT_CLASS */
  213. {
  214.    { OGTAR_FullFileName, OGTSL_FileToLoadByName },
  215.    { TAG_DONE                                   }
  216. };
  217.  
  218. Tag Obj1toObj4Filter[] =
  219. {
  220.    OGTAR_FullFileName,
  221.    TAG_DONE
  222. };
  223.  
  224.  
  225. struct OGT_ObjectLink ListOfLinks[] =
  226. {
  227.    { 3           , 1, Obj4toObj2, Obj4toObj2Filter },
  228.    { 3           , 2, Obj4toObj3, Obj4toObj3Filter },
  229.    { 1           , 3, Obj2toObj4                   },
  230.    { 2           , 3, Obj3toObj4                   },
  231.  
  232.    { 0           , 3, Obj1toObj4, Obj1toObj4Filter },
  233.    { 3           , 0, Obj4toObj1, Obj4toObj1Filter },
  234.  
  235.    { OGT_NOOBJECT                                  },
  236. };
  237.  
  238.  
  239. static int cleanup( char *str );
  240.  
  241. int main( void )
  242. {
  243.    if(!OpenOGT()) cleanup( "no objectivegadtools.library!\n" );
  244.  
  245.    if(!(Ra = ReadArgs( ARGS_TEMPLATE, args, NULL ))) return( cleanup( "Can't parse args\n" ) );
  246.  
  247.    if(args[ ARGS_FONT ]) MyAttr.ta_Name  =  (STRPTR )args[ ARGS_FONT ];
  248.    if(args[ ARGS_SIZE ]) MyAttr.ta_YSize = *(ULONG *)args[ ARGS_SIZE ];
  249.  
  250.    if(MyAttr.ta_Name)
  251.    {
  252.       if(!(MyFont = OpenDiskFont( &MyAttr ))) return( cleanup( "Can't open font!!\n" ) );
  253.    }
  254.  
  255.    while(1)
  256.    {
  257.       VInfo = OGT_GetVisualInfo( NULL, OGT_TextFont, (ULONG)MyFont         ,
  258.                                        TAG_MORE    , (ULONG)WindowDescTags );
  259.  
  260.       if(VInfo == NULL) return( cleanup( "Can't open my window.\n" ) );
  261.  
  262.       Object1Post[ 0 ].ti_Data = args[ ARGS_FILE ];
  263.  
  264.       if(!OGT_BuildObjects( VInfo, ListOfObjects, ListOfLinks, &Gads )) return( cleanup( "can't create objects" ) );
  265.  
  266.       Win = OGT_GetWindowPtr( VInfo );
  267.  
  268.       {
  269.          BOOL keeprunning = TRUE;
  270.  
  271.          while(keeprunning)
  272.          {
  273.             struct IntuiMessage *imsg;
  274.  
  275.             Wait( 1L << Win->UserPort->mp_SigBit );
  276.  
  277.             while(keeprunning && (imsg = OGT_GetMsg( VInfo )))
  278.             {
  279.                switch(imsg->Class)
  280.                {
  281.                   case IDCMP_CLOSEWINDOW:
  282.                      keeprunning = FALSE;
  283.                      break;
  284.                }
  285.  
  286.                OGT_ReplyMsg( imsg );
  287.             }
  288.          }
  289.       }
  290.  
  291.       break;
  292.    }
  293.  
  294.    return( cleanup( NULL ) );
  295. }
  296.  
  297. static int cleanup( char *str )
  298. {
  299.    if(str) Printf( "%s\n", str );
  300.  
  301.    if(Ra    ) FreeArgs          ( Ra     );
  302.    if(Gads  ) FreeVec           ( Gads   );
  303.    if(VInfo ) OGT_FreeVisualInfo( VInfo  );
  304.    if(MyFont) CloseFont         ( MyFont );
  305.  
  306.    CloseOGT();
  307.  
  308.    return( str ? 10 : 0 );
  309. }
  310.